package BiShi.tengxun;

import java.util.LinkedList;
import java.util.Scanner;

public class Main5 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkedList<Integer> q = new LinkedList<>();
        while(sc.hasNext()){
            int n = sc.nextInt();
            int[][] a = new int[n][2];
            for (int i = 0; i < n; i++)
            {
                 a[i][0] = sc.nextInt();
                 a[i][1] = sc.nextInt();
            }

            for (int i = 0; i < n; i++)
            {
              int  aa =  a[i][0] ;
              int  bb =  a[i][1] ;
                System.out.println(helper(aa, bb));
            }
        }
    }

    private static int helper(int a, int b) {
        int po = 0;
        while (true){
            if(a > Math.pow(2, po)){
                po++;
                continue;
            }
            break;
        }
        if(po <= b){
            return -1;
        }
        int t = po - b;
        while(t-- > 0){
            a = a /2;
        }
        return a;
    }
}



